import datetime
import json

from flask import Request




def handler_request_log(request:Request, status_code, resp,modb,is_json=False):
    try:
        data = None
        data = {"request_url": request.url,
                "request_form": request.form if request.form else "",
                "request_args": request.args if request.args else "",
                "status_code": status_code,
                "resp": resp
            , "create_time": datetime.datetime.now().isoformat() + "Z"}
        if is_json:
            data['request_json'] = request.json
        rows = modb.insert_data(data)
    except Exception as e:
        raise Exception("handler_request_log失败",e)
